package com.auto.learning.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.auto.learning.R;
import com.auto.learning.bean.BookBean;
import com.nostra13.universalimageloader.core.ImageLoader;

public class LichengBooklistAdapter extends BaseAdapter{
	
	private Context context;
	private ArrayList<BookBean> list;
	
	public LichengBooklistAdapter(Context context,ArrayList<BookBean> list){
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return list.get(position).getBookId();
	}

	ViewHolder holder;
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.licheng_gv_adapter, null);
			holder.image_book_face = (ImageView) convertView.findViewById(R.id.image_book_face);
			holder.f_image_is_new = (ImageView) convertView.findViewById(R.id.f_image_is_new);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		ImageLoader.getInstance().displayImage(list.get(position).getFaceImg(), holder.image_book_face);
		if (list.get(position).getIsNew() == 2) {
			holder.f_image_is_new.setVisibility(View.VISIBLE);
		}else {
			holder.f_image_is_new.setVisibility(View.GONE);
		}
		return convertView;
	}
	
	class ViewHolder{
		ImageView image_book_face,f_image_is_new;
	}

}
